package com.allin.plugin1;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

//import com.allin.pluginlibrary.AppConstants;
//import com.allin.pluginlibrary.activity.BasePluginActivity;
import com.allin.pluginlibrary.activity.BasePluginActivity;

/**
 * ${CLASS} class
 *
 * @author tzy
 * @date 2021/03/08
 */
public class MainActivity extends BasePluginActivity {

    private static final String TAG = "Client-MainActivity";

    Button button2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        //startActivity，插件内跳转
        Button button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(AppConstants.PROXY_VIEW_ACTION);
//                intent.putExtra(AppConstants.EXTRA_DEX_PATH, dexPath);
//                intent.putExtra(AppConstants.EXTRA_CLASS, SecondActivity.class.getCanonicalName());
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                intent.putExtra("userName", "tzy1");
                startActivity(intent);

            }
        });

        //startActivityForResult
        button2 = (Button) findViewById(R.id.button2);
        button2.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(AppConstants.PROXY_VIEW_ACTION);
//                intent.putExtra(AppConstants.EXTRA_DEX_PATH, dexPath);
//                intent.putExtra(AppConstants.EXTRA_CLASS, "com.allin.plugin1.TestActivity");
                Intent intent = new Intent(MainActivity.this, TestActivity.class);
                intent.putExtra("userName", "tzy2");
                startActivityForResult(intent, 0);
            }
        });

        //跳转到宿主其它Activity
        Button button3 = (Button) findViewById(R.id.button3);
        button3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("userName", "tzy");
                ComponentName componentName = new ComponentName("com.hostapp.demo", "com.hostapp.demo.MainActivity");
                intent.setComponent(componentName);
                startActivity(intent);
            }
        });

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 0 && resultCode == 2) {
            String userName = data.getStringExtra("username");
            button2.setText(button2.getText() + userName);
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
}